import {
  applyJoinGroup,
  groupQRcode
} from '../../apis/group';
import {
  globalData
} from '../../utils/request';
const app = getApp();

Page({
  data: {
    inputValue: ''
  },

  onLoad(options) {
    this.setData({
      ...options,
      showGroupBtn: globalData.checkIn
    });
    this.getBasicInfo(options.groupId);
  },

  // 未加入群组时获取基本信息
  getBasicInfo(id) {
    groupQRcode(id).then(res => {
      if (res.data.code === 200) {
        this.setData({
          groupInfo: res.data.data
        });
      };
    });
  },

  handleInput(e) {
    let {
      value
    } = e.detail;
    this.setData({
      inputValue: value
    });
  },

  applyJoin() {
    applyJoinGroup(this.data.groupId, this.data.cardId, this.data.inputValue).then(res => {
      if (res.data.code === 200) {
        wx.showToast({
          title: '已提交',
          duration: 1500,
          icon: 'success',
          mask: true,
          success: res => {
            setTimeout(() => {
              wx.navigateBack({
                delta: 1
              });
            }, 1500);
          }
        });
      };
    });
  }
})